package com.lsa.skienna.challenge.chap13.the111301_DogAndGopher;

import java.awt.geom.Point2D;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Formatter;
import java.util.List;
import java.util.Locale;
import java.util.Scanner;

public class Main implements Runnable{
    static class TaskReader{
        private Scanner scanner;

        TaskReader(InputStream stream) {
            this.scanner = new Scanner(stream);
            scanner.useLocale(Locale.ENGLISH);
        }
        
        Task nextTask() throws IOException {
            if (!scanner.hasNextInt()) {
                return null;
            }
            
            Task task = new Task();
            int holeCount = scanner.nextInt();
            
            task.gopherCoords = readPointCoords();
            task.dogCoords = readPointCoords();

            for (int i = 0; i < holeCount; i++) {
                task.gopherHoles.add(readPointCoords());
            }
            
            return task;
        }
        
        Point2D.Float readPointCoords() {
            return new Point2D.Float(scanner.nextFloat(), scanner.nextFloat());
        }
    }
    
    static class Task {
        Point2D.Float dogCoords;
        Point2D.Float gopherCoords;
        
        List<Point2D.Float> gopherHoles = new ArrayList<Point2D.Float>();
    }
    
    public static void main(String[] args) throws Exception {
        new Main().run();
    }

    @Override
    public void run() {
        process(System.in, System.out);
    }
    
    static void process(InputStream in, PrintStream out) {
        TaskReader taskReader = new TaskReader(in);
        try {
            Task task = null;
            while((task = taskReader.nextTask()) != null){
                out.println(solve(task));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    
    static String solve(Task task) {
        final List<Point2D.Float> gopherHoles = task.gopherHoles;
        Point2D.Float safeHole = null;
        boolean isCanEscape = false;
        for (Point2D.Float hole : gopherHoles) {
            float dogDistSquared = distanceSquared(task.dogCoords, hole);
            float gopherDistSquared = distanceSquared(task.gopherCoords, hole);
            if (dogDistSquared < 4 * gopherDistSquared) {
                continue;
            }
            else {
                isCanEscape = true;
                safeHole = hole;
                break;
            }
        }
        
        if (isCanEscape) {
            return new Formatter(Locale.ENGLISH).format("The gopher can escape through the hole at (%.3f,%.3f).", safeHole.x, safeHole.y).toString();
        }
        else{
            return "The gopher cannot escape.";
        }
    }
    
    static float distanceSquared(Point2D.Float from, Point2D.Float to) {
        return square(to.x - from.x) + square(to.y - from.y);
    }
    
    static float square(float x) {
        return x*x;
    }
}
